<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>注册</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />

    <link charset="utf-8" rel="stylesheet" media="screen" type="text/css" href="css/929fce5888dcb6d8980fc7174f81d92d.css?mod=1422952910"
    />
    <link charset="utf-8" rel="stylesheet" media="screen" type="text/css" href="css/787419f4fe554ed02037dc0cd5d765b6.css?mod=1421661595"
    />
    <!--导航公共-->
    <link charset="utf-8" rel="stylesheet" media="screen" type="text/css" href="css/9a3fbe3acd45615db0b546121dd02187.css?mod=1429666776"
    />
    <script charset="utf-8" src="http://wpa.b.qq.com/cgi/wpa.php"></script>
    <script charset="utf-8" src="js/jquery-3.2.1.min.js"></script>
</head>

<body>
    <div class="com_top" >
        <div class="wrap">
            <div class="com_top_l fl" >
                <a href="index.html">首页</a>
                <a class="welcome">欢迎来到水晶王国&nbsp;&nbsp;</a>
                <a id="Login" class="login" href="#formLoginRegis"></a>
                <a class="login" href="login.html">请登录</a>
                <a href="reg.html">免费注册</a>
            </div>
</div>
</div>

            <div class="register" style="padding-top: 200px;">
                <div class="register-infobox step1">
                    <form id="member_register_form" method="post">
                        <input type="hidden" name="http_referer" value="cart.html" />
                        <div class="register-row">
                            
                                <div class="register-row-left">
                                    <em>*</em>用户昵称:
                                </div>
                                <div class="register-row-input">
                                    <div class="input-box">
                                        <input class="pub-input phone" name="nickName" type="text" id="nickName">
                                    </div>
                                    <!-- <div class="tips"></div> -->
                                    <!-- <div class="phone-error">亲，您输入的手机号码有误！</div> -->
                                </div>
                            </div>


                        <div class="register-row">
                            
                            <div class="register-row-left">
                                <em>*</em>手机号码:
                            </div>
                            <div class="register-row-input">
                                <div class="input-box">
                                    <input class="pub-input phone" name="register_mobile" type="text" id="moblic_reg_input">
                                </div>
                                <div class="tips"></div>
                                <div class="phone-error">亲，您输入的手机号码有误！</div>
                            </div>
                        </div>
                        <div class="register-row">
                            <div class="register-row-left" v-model="phone" id="phone">
                                <em>*</em>验证码：
                            </div>
                            <div class="register-row-input">
                                <input class="pub-input" style="width: 72px;" id="register_verify_code" name="register_verify_code" />
                                <a class="pub-btn-small-green" href="javascript:void(0)" group="" id="register_get_code">获取验证码
                                    <span id="second_timer"></span>
                                </a>
                                <div class="tips" style="width:82px;"></div>
                            </div>
                        </div>

                        <div class="register-row">
                            <div class="register-row-left" v-model="password" id="password">
                                <em>*</em>登录密码:
                            </div>
                            <div class="register-row-input">
                                <input class="pub-input password" name="register_pwd" type="password" id="password_reg_input">
                                <div class="tips"></div>
                                <div class="password-level">
                                    <span class="low">低</span>
                                    <span class="middle">中</span>
                                    <span class="high">高</span>
                                </div>
                            </div>
                        </div>
                        <div class="register-row" style="margin-top:40px;">
                            <div class="register-row-left" v-model="confirmpw" id="confirmpw">
                                <em>*</em>支付密码:
                            </div>
                            <div class="register-row-input">
                                <input class="pub-input re-password" name="repassword" type="password" id="repassword_reg_input">
                                <div class="tips"></div>
                            </div>
                        </div>
                        <div class="register-row" style="margin-top:40px;">
                                <div class="register-row-left" v-model="confirmpw" id="confirmpw">
                                    <em>*</em>推荐码:
                                </div>
                                <div class="register-row-input">
                                    <input class="pub-input re-password" name="promotionCode" type="password" id="promotionCode">
                                    <div class="tips"></div>
                                </div>
                            </div>
                        <div class="register-row" style="height:44px; margin-top:20px;">
                            <div class="register-row-left">
                            </div>
                            <div class="register-row-input" style="height:44px; overflow:hidden;">
                                <a class="pub-btn-big-orange" id="register_submit_button">确定</a>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="register-textinfo">
                    <!-- style="cursor:pointer;"  onclick="location.href='http://www.chemayi.com/subject/index/type-aichejie.html';"-->
                    <img src="images/home.png" border="0" />
                    <!-- usemap="#Map"  -->
                </div>
            </div>



            <script type="text/javascript">
                $(function () {
                    $(".register-row-input .pub-input").on("focus", function () {
                        $(this).parents(".register-row-input").removeClass("error");
                    });
                    $(".register-row-input .tips").on("click", function () {
                        var obj = $(this).parents(".register-row-input");
                        obj.removeClass("error");
                        obj.find("input").focus();
                    });

                    $("input[name=register_mobile]").on("blur", function () {
                        if (VerifyMobile(this)) {
                            $(this).attr("verify-finish", true);
                        }
                    });
                    $("input[name=register_pwd]").on("blur", function () {
                        if (VerifyPassword(this)) {
                            $(this).attr("verify-finish", true);
                        }
                    });
                    // $("input[name=repassword]").on("blur", function() {
                    //     if (VerifyRePassword(this)) {
                    //         $(this).attr("verify-finish", true);
                    //     }
                    // });
                    $("input[name=register_verify_code]").on("blur", function () {
                        if (VerifyVerifyCode(this)) {
                            $(this).attr("verify-finish", true);
                        }
                    });

                    $("#register_get_code").on("click", function () {
                        if ($(this).hasClass("on")) {
                            return false;
                        }
                        if ($("input[name=register_mobile]").attr("verify-finish")) {
                            var self = $(this);
                            self.html("正在发送").addClass('on');
                            // $.ajax({
                            //     url: "http://192.168.0.120/api/regcodes.html",
                            //     dataType: "json",
                            //     async: true,
                            //     data: "phone=" + $("input[name=register_mobile]").val(),
                            //     type: "POST",
                            //     timeout: 30000,
                            //     error: function() {
                            //         //$.notice('请刷新页面并重新操作','error');
                            //         $.notice('验证码发送失败', 'error');
                            //         self.html("发送验证码").removeClass("on");
                            //         return false;
                            //     },
                            //     success: function() {
                            //         var html = '验证码已发送(<i>30</i>)';
                            //         self.html(html);
                            //         regCodeInterval = setInterval(function() {
                            //             regCodeTimeinterval();
                            //         }, 1000);
                            //     }
                            // });
                            $.post('http://192.168.0.120/api/regcodes.html', {
                                phone: $('#moblic_reg_input').val()
                            }, (data) => {
                                var html = '验证码已发送(<i>30</i>)';
                                self.html(html);
                                console.log(data);
                                regCodeInterval = setInterval(function () {
                                    regCodeTimeinterval();
                                }, 1000);
                            })
                        }
                    });


                    /* 验证手机 */
                    function VerifyMobile(id) {
                        var mobile = $(id).val(),
                            msg = "",
                            slef = $(id),
                            parent = $(id).parents(".register-row-input"),
                            tip = parent.find(".tips");
                        if (mobile == "") {
                            msg = "请输入您的手机号";
                            tip.html(msg);
                            parent.addClass("error");
                            $(id).val("");
                            return false;
                        } else if (!/^0?1[34578]\d{9}$/.test(mobile)) {
                            msg = "手机号码格式错误";
                            tip.html(msg);
                            parent.addClass("error");
                            $(id).val("");
                            return false;
                        } else {
                            $.ajax({
                                dataType: "json",
                                async: false,
                                url: "http://192.168.0.120/api/regcodes.html",
                                data: "phone=" + mobile,
                                type: "POST",
                                timeout: 10000,
                                success: function (data) {
                                    if (data.result == "fail") {
                                        msg = "该手机已经被注册过";
                                        tip.html(msg);
                                        parent.addClass("error");
                                        $(id).val("");
                                        return false;
                                    } else {
                                        slef.attr("verify-finish", true);
                                    }
                                }
                            })
                        }
                        return;
                    }
                    /* 验证密码 */
                    function VerifyPassword(id) {
                        var password = $(id).val(),
                            msg = "",
                            parent = $(id).parents(".register-row-input"),
                            tip = parent.find(".tips");
                        if (password == "") {
                            msg = "请输入密码";
                            tip.html(msg);
                            parent.addClass("error");
                            $(id).val("");
                            return false;
                        }
                        if (password.length < 6) {
                            msg = "密码位数不能少于6位!";
                            tip.html(msg);
                            parent.addClass("error");
                            $(id).val("");
                            return false;
                        }
                        return true;
                    }
                    /* 验证确认密码 */
                    // function VerifyRePassword(id) {
                    //     var repassword = $(id).val(), password = $("input[name=register_pwd]").val(),
                    //             parent = $(id).parents(".register-row-input"),
                    //             tip = parent.find(".tips"), msg = "";
                    //     if (repassword == "") {
                    //         msg = "请输入确认密码";
                    //         tip.html(msg);
                    //         parent.addClass("error");
                    //         $(id).val("");
                    //         return false;
                    //     }
                    //     if (repassword != password) {
                    //         msg = "两次密码输入不一致";
                    //         tip.html(msg);
                    //         parent.addClass("error");
                    //         $(id).val("");
                    //         return false;
                    //     }
                    //     return true;
                    // }
                    /* 检测验证码 */
                    function VerifyVerifyCode(id) {
                        var code = $(id).val(),
                            msg = "",
                            parent = $(id).parents(".register-row-input"),
                            tip = parent.find(".tips");
                        if (code == "") {
                            msg = "请输入验证码";
                            tip.html(msg);
                            parent.addClass("error");
                            $(id).val("");
                            return false;
                        }
                        return true;
                    }
                    /* 密码安全程度 */
                    $('#password_reg_input').bind('keyup', function () {
                        $('.password-level').removeClass('level1');
                        $('.password-level').removeClass('level2');
                        $('.password-level').removeClass('level3');

                        var password = $(this).val();
                        if (/^[0-9]+$/.test(password) || /^[a-z]+$/.test(password)) {
                            $('.password-level').addClass('level1');
                        } else if (/^[0-9|a-z]+$/.test(password)) {
                            $('.password-level').addClass('level2');
                        } else if (/^[0-9|a-z|\D|^0-9|^a-z]+$/.test(password)) {
                            $('.password-level').addClass('level3');
                        }
                    });
                    /*  */
                    function regCodeTimeinterval() {
                        var currTime = $('#register_get_code i').html();
                        var newTime = parseInt(currTime) - 1;
                        if (newTime) {
                            $('#register_get_code i').html(newTime);
                        } else {
                            clearInterval(regCodeInterval);
                            $('#register_get_code').html('重新发送').removeClass('on');
                        }
                    }

                    //将注册提交绑定提交按钮
                    $("#register_submit_button").click(function () {
                        var prama = {
                            floginName:$('#moblic_reg_input').val(),
                            floginPassword:$('#password_reg_input').val(),
                            fTradePassword:$('#repassword_reg_input').val(),
                            valiCode:$('#register_verify_code').val(),
                            promotionCode:$('#promotionCode').val(),
                            fnickName:$('#nickName').val(),
                        }   
                        console.log(prama);
                           $.post('http://192.168.0.120/api/register.html',prama,(data)=>{
                               if(data.status == '1'){
                                window.location.href='login.html';
                               }
                           })
                        

                    });
                })
            </script>
</body>

</html>